# @Version        : 1.0
# @Update Time    : 2025/8/23 0:00
# @File           : register.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
from contextlib import asynccontextmanager
from typing import AsyncGenerator

from fastapi import FastAPI
from tortoise.contrib.fastapi import RegisterTortoise

from applications import settings


@asynccontextmanager
async def on_lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
    async with RegisterTortoise(
        app,
        db_url=settings.DATABASE_URI,
        # config=settings.TORTOISE_ORM,
        modules={"models": ["applications.models"]},
        use_tz=False,
        timezone="Asia/Shanghai",
    ):
        # db connected
        print("启动")
        yield
        print("关闭")
